package com.bwie.redis;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import redis.clients.jedis.Jedis;

@Component
public class RedisListener implements CommandLineRunner {

    @Autowired
    private RedisKeyExpirationListener redisKeyExpirationListener;

    @Override
    public void run(String... args) throws Exception {
        new Thread(() -> {
            try (Jedis jedis = new Jedis("192.168.80.192", 6379)) {
                // 订阅 Redis 的过期事件
                jedis.psubscribe(redisKeyExpirationListener, "__key*__:*");
            }
        }).start();
    }
}
